$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'edu/coursing/query',
        datatype: "json",
        colModel: [
            { label: '课程编号', name: 'courseSno', width: 40 },
            { label: '课程名称', name: 'courseName', width: 40 },
            { label: '上课班级', name: 'bname', width: 40 },
            { label: '人数', name: 'renshu', width: 20 },
            { label: '签到', name: 'ids', width: 40 ,formatter:function(value,options,rowData){
             return '<span onclick="qdao(\''+ value+ '\');" style="cursor:pointer" class="label label-success">开始签到</span>';
            }}
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,

        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
    el:'#rrapp',
    data:{

        showList: true,//div 的隐藏和显示
        title: null,

    },
    created:function(){

    },
    methods: {

        query: function () {
            vm.reload();
        },
        add: function(){

            vm.showList = false;
            vm.title = "签到";
            var qrcode = new QRCode(document.getElementById("qrcode"), {
                width : 500,
                height : 500
            });
            qrcode.makeCode("www.baidu.com");


        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            page ="1";
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{},
                page:page
            }).trigger("reloadGrid");
        }
    }
});
//var url ="http://localhost:80/dingo.html?";
var url ="http://hrbhxci.com/dingo.html?";
var data= {};
$("#submitBtn").click(function () {
    var t = $("#time").val();
    var d = $("#date").val();

    if (t == "" || d ==""){
       $("#error").css('display','block');
    }else if(t != '' && !isNaN(t) && parseInt(t) >30){
        $("#error").css('display','block');
        $("#es").text("设置迟到时间不能超过30分钟")
    } else{
        $('#myModal').modal('hide');
        vm.showList = false;
        vm.title = "签到";
        var qrcode = new QRCode(document.getElementById("qrcode"), {
            width : 500,
            height : 500
        });


        data.sksj=d;
        $.ajaxSettings.async = false;
        $.post(baseURL+"edu/coursing/batchAdd",data,function(r){
            data.timer=r.timer;
            data.recordid=r.ids;
        })
        $.ajaxSettings.async = true;

        url =url+data.recordid+"&"+t+"&"+ data.timer;

        // console.log(url)

        qrcode.makeCode(url);
        $("#showm").attr("style","display:block;")
    }


})
function qdao(e) {




    $('#myModal').modal('show') //显示模态框
    var arr =e.split(",")
    var rs =0;
    var bj =[];
    $.each(arr,function (i,v) {
       a = v.split("-");
       rs =rs + parseInt(a[3]);
       bj.push(a[1]);
    })
    $('#yd').text(rs);

    var arr2 =arr[0].split("-")
    var k =arr2[0];
    var t =arr2[2];


    data.bjs=bj;
    data.cid=k;
    data.tid=t;
    data.renshu=rs;

}
function refreshData () {
    //http://192.168.120.249/index.html?32&102&1-2&5&1647051523587

    $.post(baseURL+"edu/coursing/check",data,function(r){

        $("#tabProduct1").empty();$("#tabProduct2").empty();
        var t1='<tr>' +
            '<td width="120" bgcolor="#EFEFEF" >序号</td>' +
            '<td width="103" bgcolor="#EFEFEF"  >学号</td>' +
            '<td width="103" bgcolor="#EFEFEF"  >姓名</td>' +
            '<td width="103" bgcolor="#EFEFEF"  >班级</td>' +
            '<td width="152" bgcolor="#EFEFEF" >状态</td>' +
            '</tr>';
        var t2='<tr>' +
            '<td width="120" bgcolor="#EFEFEF" >序号</td>' +
            '<td width="103" bgcolor="#EFEFEF"  >学号</td>' +
            '<td width="103" bgcolor="#EFEFEF"  >姓名</td>' +
            '<td width="103" bgcolor="#EFEFEF"  >班级</td>' +
            '<td width="152" bgcolor="#EFEFEF" >状态</td>' +
            '</tr>';
        var a =0;
        var b =0;
        $.each(r.list,function (i,v) {
            if( v.status == 1 || v.status == 2){

                t1 =t1+' <tr>' +
                    '<td >'+(a+1)+'</td>' +
                    '<td>'+v.sno+'</td>' +
                    '<td>'+v.sname+'</td>' +
                    '<td>'+v.bname+'</td>' +
                    '<td>'+v.statusName+'</td>' +
                //     '<td><select id="'+v.id+'" onchange="status(\'' + v.id + '\')">' +
                // '<option value="1" selected>已签到</option>' +
                // '<option value="2">迟到</option>' +
                // '<option value="3">请假</option>' +
                // '<option value="4">旷课</option>' +
                // '</select></td>' +
                    '</tr>';
                a=a+1;
            }else {

                t2 =t2+' <tr>' +
                    '<td >'+(b+1)+'</td>' +
                    '<td>'+v.sno+'</td>' +
                    '<td>'+v.sname+'</td>' +
                    '<td>'+v.bname+'</td>' +
                    '<td>'+v.statusName+'</td>' +
                    // '<td><select id="'+v.id+'" onchange="status(\'' + v.id + '\')">' +
                    // '<option value="1" >已签到</option>' +
                    // '<option value="2" selected>迟到</option>' +
                    // '<option value="3">请假</option>' +
                    // '<option value="4">旷课</option>' +
                    // '</select></td>' +
                    '</tr>';
                b=b+1;
            }
            $('#sd').text(a);
            $('#qd').text(b);
            // else if( v.status == 3){
            //
            //     t2 =t2+' <tr>' +
            //         '<td >'+b+'</td>' +
            //         '<td>'+v.sno+'</td>' +
            //         '<td>'+v.sname+'</td>' +
            //         '<td>'+v.statusName+'</td>' +
            //         '<td><select id="'+v.id+'" onchange="status(\'' + v.id + '\')">' +
            //         '<option value="1" >已签到</option>' +
            //         '<option value="2" >迟到</option>' +
            //         '<option value="3" selected>请假</option>' +
            //         '<option value="4">旷课</option>' +
            //         '</select></td>' +
            //         '</tr>';
            //     b=b+1;
            // }else if( v.status == 4){
            //
            //     t2 =t2+' <tr>' +
            //         '<td >'+b+'</td>' +
            //         '<td>'+v.sno+'</td>' +
            //         '<td>'+v.sname+'</td>' +
            //         '<td>'+v.bname+'</td>' +
            //         '<td><select id="'+v.id+'" onchange="status(\'' + v.id + '\')">' +
            //         '<option value="1" >已签到</option>' +
            //         '<option value="2" >迟到</option>' +
            //         '<option value="3" >请假</option>' +
            //         '<option value="4" selected>旷课</option>' +
            //         '</select></td>' +
            //         '</tr>';
            //     b=b+1;
            // }

        });

        $("#tabProduct1").append(t1)//返回的JSON数据
        $("#tabProduct2").append(t2)
    },"json")
}
// function status(e) {
//     if(e==1){alert("该同学未扫码，不能更改");return}
//     $.post(baseURL+"edu/coursing/change",{"id":e,"status":$("#"+e+"").val()},function(r){
//         refreshData ();
//     });
// }